package fr.utbm.gi.vi51.slizers.pw.learning;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.bouncycastle.util.Store;

import fr.utbm.gi.vi51.slizers.framework.learning.QAbstractProblem;
import fr.utbm.gi.vi51.slizers.pw.agent.action.CreatureAction;

public class CreatureQProblem extends QAbstractProblem<CreatureQState, CreatureQAction> {

	/**
	 *  Current state of the problem
	 */
	CreatureQState currentState;
	
	private final List< CreatureQAction > availableActions;
		
	/**
	 * Parameterized constructor.
	 * 
	 * @param _alphaLearningRate the learning rate
	 * @param _gammaDiscountRate the discount rate
	 * @param _rho the rho value
	 * @param _nu the nu value
	 */
	public CreatureQProblem( float _alphaLearningRate,
			float _gammaDiscountRate, float _rho, float _nu )
	{
		super( _alphaLearningRate, _gammaDiscountRate, _rho, _nu );
		this.availableActions = new ArrayList< CreatureQAction >();
		initAvailableActions();
	}

	/* (non-Javadoc)
	 * @see fr.utbm.gi.vi51.slizers.framework.learning.QAbstractProblem#getCurrentState()
	 */
	@Override
	public CreatureQState getCurrentState() {
		return this.currentState;
	}

	/* (non-Javadoc)
	 * @see fr.utbm.gi.vi51.slizers.framework.learning.QProblem#getRandomState()
	 */
	@Override
	public CreatureQState getRandomState() {
		int numStates = CreatureState.values().length;
		CreatureState s = CreatureState.values()[(int)(Math.random() * numStates)];
		return new CreatureQState(s);
	}

	/* (non-Javadoc)
	 * @see fr.utbm.gi.vi51.slizers.framework.learning.QProblem#setCurrentState(fr.utbm.gi.vi51.slizers.framework.learning.QState)
	 */
	@Override
	public void setCurrentState(CreatureQState _state) {
		this.currentState =  _state;
	}

	/* (non-Javadoc)
	 * @see fr.utbm.gi.vi51.slizers.framework.learning.QProblem#getAvailableStates()
	 */
	@Override
	public List<CreatureQState> getAvailableStates() {
		List<CreatureQState> ret = new ArrayList<CreatureQState>();
		for(CreatureState state : CreatureState.values()) {
			ret.add(new CreatureQState(state));
		}
		return ret;
	}

	/* (non-Javadoc)
	 * @see fr.utbm.gi.vi51.slizers.framework.learning.QAbstractProblem#getAvailableActionsFor(fr.utbm.gi.vi51.slizers.framework.learning.QState)
	 */
	@Override
	public List<CreatureQAction> getAvailableActionsFor(CreatureQState _state) {
		return availableActions;
	}

	/**
	 * Initialize the list of available actions.
	 */
	public void initAvailableActions() {
		for ( CreatureAction action : CreatureAction.values() )
		{
			this.availableActions.add( new CreatureQAction( action ) );
		}
	}

}
